vimfandomcom-20200223-history
Mighty Mouse
As much as it is against the Vim-way of doing things, it would be nice to have the mouse do the right thing when it is used once in a while. This tip refines tip Use Alt-Mouse to select blockwise for gvim. Holding down Alt + dragging the left mouse button will activate the Visual Block, much like how MS Word works. Holding down Shift + dragging will switch it back to Visual mode, and vice versa. Insert-VisualBlock mode is called if mouse highlight is activated from Insert mode. This tip also fixes some issues with the default Alt/Shift + clicking to make it work more seamlessly. This tip also attempts to resolve an issue that was brought up in the Vim mailing list: *Console/terminal* Vims that are not compiled with the +xterm_clipboard option (see :version) have trouble pasting from external sources. They are not able to access the clipboard, and have to make use of the middleclick paste function. Unfortunately, if the mouse option was set as ':set mouse=a', the middleclick paste will not help. On the other hand, if the mouse option wasn't set, the middleclick paste would work fine, but instead, many of the console mouse functionalities such as positioning, wheel-scrolling and window sizing would not work. This is fixed by only allowing middleclick paste to work in Insert mode. Extended mouse functionalities are sacrificed in Insert mode but will work in other modes like Normal and Visual modes.When a middleclick paste is issued in Normal mode, it switches to Insert mode to do the paste. If it is issued in Visual mode, it cuts the highlighted text, and switches to Insert mode to do the paste to simulate a "paste over selection". To avoid indentation when middleclick pasting: hit first to enable paste mode, middleclick, and hit again to disable paste mode (see ). "place in vimrc set nopaste if has("gui_running") "mouse visual block (ala MS Word) nmap ms`so imap `^msgi`so vmap vmap msgv`s vmap vmsgv`s set mouse=ra else "paste toggle nmap :set paste! paste? imap :set paste! vmap :set paste!gv "xterm mouse with middleclick paste nnoremap i vnoremap s set pastetoggle= mouse=rnv "choose either one set ttymouse=xterm "set ttymouse=xterm2 endif Comments I don't know why, but your tip for blockwise selection doesn't work for me. But it inspired me to look for a solution and the following lines do a blockwise selection for me. "mouse visual block (ala MS Word) nmap vmap imap vmap The tip makes use of mark s, so make sure it's not already used. Also, I tested it with Vim 6.3 and above. What version of Vim are you using? It's good that you found a mapping that works for you. I tailored the mappings above so that it tries to be as faithful to the current mode that you are in. For instance, performing when in Insert mode block highlights, visually, from the position of the cursor to the position of the leftclick, invoking Insert-Visual mode (not Visual-only mode). I believe Vim 7 has native Visual Block mouse support. ---- Does Vim 7 really have Visual Block mouse support? If so, how is it used? I don't see any documentation of this, and a little experimenting shows that , , and don't initiate block-selection. --February 11, 2014 :The mouse can be used if options are set correctly. For example, after :set mousemodel=extend, you can left-click to set an initial position, then hold down Alt and right-click at another position to select a visual block ( ). Another method that is convenient for occasional use is to use :set mousemodel=popup then left-click to set an initial position, then hold down Shift and left-click at another position. That gives a character-wise selection. Then type Ctrl-V (or Ctrl-Q if Ctrl-V is mapped to paste) to change to block-wise. JohnBeckett (talk) 07:16, February 11, 2014 (UTC)